/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Client;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;

/**
 * 
 * @author TienNT
 */
public class Client extends Thread {

	Socket mSocket;
	DataInputStream mFromServer;
	DataOutputStream mToServer;

	String mClientName = "";
	Client_Login mClientLoginForm;
	Client_Dashboard mClientDashboard;

	int mStatus = ClientUtils.NOT_CONNECTED;

	public String getClientName() {
		return mClientName;
	}

	public void setClientName(String name) {
		mClientName = name;
	}

	public Socket getSocket() {
		return mSocket;
	}

	public DataInputStream getInputStream() {
		return mFromServer;
	}

	public DataOutputStream getOutputStream() {
		return mToServer;
	}

	public int getStatus() {
		return mStatus;
	}

	public void setStatus(int status) {
		mStatus = status;
	}

	public Client() {
		try {
			mSocket = new Socket("localhost", 1233);
			mFromServer = new DataInputStream(mSocket.getInputStream());
			mToServer = new DataOutputStream(mSocket.getOutputStream());
		} catch (IOException ex) {
			System.err.println(ex.getMessage());
		}
	}

	@Override
	public void run() {
		// TODO Auto-generated method stub

		while (true) {
			try {
				Thread.sleep(100);
			} catch (InterruptedException ex) {

			}
			switch (mStatus) {
			case ClientUtils.NOT_CONNECTED:
				if (mClientLoginForm == null) {
					mClientLoginForm = new Client_Login(this);
					mClientLoginForm.setVisible(true);
				}
				break;
			case ClientUtils.CONNECTED:
				if (mClientDashboard == null) {
					mClientDashboard = new Client_Dashboard(this);
					mClientDashboard.setVisible(true);
					new Thread(mClientDashboard).start();
				} else {

				}
				break;
			default:
				break;
			}
		}
	}

	public static void main(String[] args) {
		new Client().start();
	}
}
